package operations

import (
	"fmt"
	"github.com/sirupsen/logrus"
	"io"
	"mydocker/common"
	"mydocker/container"
	"os"
	"path"
)

// LookContainerLog 查看容器内日志信息
func LookContainerLog(containerID string) {
	logFilePath := path.Join(common.DefaultContainerInfoPath, containerID, container.GetLogFile(containerID))
	file, err := os.Open(logFilePath)
	if err != nil {
		logrus.Errorf("open log file, path: %s, err: %v", logFilePath, err)
	}
	defer file.Close()
	content, err := io.ReadAll(file)
	if err != nil {
		logrus.Errorf("read log file, path: %s, err: %v", logFilePath, err)
	}
	_, err = fmt.Fprint(os.Stdout, string(content))
	if err != nil {
		logrus.Errorf("Log container Fprint error %v", err)
		return
	}
}
